package web.utils;

import common.consts.Header;

import javax.servlet.http.HttpServletRequest;

public final class IpUtil {

    public static String getClientIp(HttpServletRequest request) {
        String ip = request.getHeader(Header.X_FORWARD_FOR);
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader(Header.PROXY_CLIENT_IP);
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader(Header.WL_PROXY_CLIENT_IP);
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}